package cn.monkey.transport.netty.server.codec.protocol.udp;

import io.netty.channel.Channel;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.DatagramPacket;

import java.util.function.BiPredicate;

public interface UdpServerProtocolPredicate extends BiPredicate<Channel, Object> {

    UdpServerProtocolPredicate INSTANCE = new UdpServerProtocolPredicate() {
    };

    @Override
    default boolean test(Channel channel, Object data) {
        if (channel instanceof DatagramChannel datagramChannel && data instanceof DatagramPacket datagramPacket) {
            return this.test0(datagramChannel, datagramPacket);
        }
        return false;
    }

    default boolean test0(DatagramChannel datagramChannel, DatagramPacket datagramPacket) {
        return true;
    }
}
